package com.peng.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peng.model.TActivityRemark;
import com.peng.query.ActivityRemarkQuery;
import com.peng.service.TActivityRemarkService;
import com.peng.mapper.TActivityRemarkMapper;
import com.peng.util.JWTUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
* @author Love-ovo
* @description 针对表【t_activity_remark(市场活动备注表)】的数据库操作Service实现
* @createDate 2025-03-14 21:28:14
*/
@Service
public class TActivityRemarkServiceImpl extends ServiceImpl<TActivityRemarkMapper, TActivityRemark>
    implements TActivityRemarkService{

    @Autowired
    private TActivityRemarkMapper tActivityRemarkMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int saveActivityRemark(ActivityRemarkQuery activityRemarkQuery) {
        TActivityRemark tActivityRemark = new TActivityRemark();

        //把ActivityRemarkQuery对象里面的属性数据复制到TActivityRemark对象里面去(复制要求：两个对象的属性名相同，属性类型要相同，这样才能复制)
        BeanUtils.copyProperties(activityRemarkQuery, tActivityRemark);

        tActivityRemark.setCreate_time(new Date()); //创建时间

        //登录人的id
        Integer loginUserId = JWTUtils.parseUserFromJWT(activityRemarkQuery.getToken()).getId();
        tActivityRemark.setCreate_by(loginUserId); //创建人

        return tActivityRemarkMapper.insert(tActivityRemark);
    }

}




